﻿
//Joan 2008-09-25
//js for reports
function RptExportToExcel(rptType)
{
    //alert();
    //window.showModalDialog("ExportToExcel.aspx?rptType=" + rptType,'','dialogHeight:310px;dialogWidth:100px;scroll:no;hidden;resizable:no;status:no;');

    var ifrm=document.getElementById("ifrmRpt");
    ifrm.src="ExportToExcel.aspx?rptType=" + rptType;
    event.returnValue=false;
}

function RptDownloadToExcel(obj)
{

    //alert(obj.value);
    if (obj.value!="0")
    {
        //window.showModalDialog("ExportToExcel.aspx?optType=1&rptID=" + obj.value,'','dialogHeight:310px;dialogWidth:100px;scroll:no;hidden;resizable:no;status:no;');

        var ifrm=document.getElementById("ifrmRpt");
        ifrm.src="ExportToExcel.aspx?optType=1&rptID=" + obj.value;
    }
        //window.open("ExportToExcel.aspx?optType=1&rptID=" + obj.value);
    event.returnValue=false;
}
function DownLoadRpt(rptID)
{
    //alert();
    var ifrm=document.getElementById("ifrmRpt");
    ifrm.src="../Report/ExportToExcel.aspx?optType=1&rptID=" + rptID;
    
    event.returnValue=false;

}


function RptSaveToExcel(rptType)
{
//    alert(window.ActiveXObject);
//    return false;
    var txtDate=null;
    var lblErr=null;
    if (rptType.indexOf("Q")>=0)
    {
        txtDate=document.getElementById("ctl00_ContentPlaceHolder1_txtReportDate_Quarterly");
        lblErr=document.getElementById("ctl00_ContentPlaceHolder1_divError_Quarterly");
    }
    else
    {
        txtDate=document.getElementById("ctl00_ContentPlaceHolder1_txtReportDate");
        lblErr=document.getElementById("ctl00_ContentPlaceHolder1_divError");
    }
    
    if (txtDate!=null)
    {
       if (checkDate(txtDate)!="success")
       {
            alert("请输入正确的日期!\nPlease specify a correct date!");
            return false;
       }
       if (confirm("时间为：" + txtDate.value +"\n您确定要保存吗？\nAre you sure to save?"))
       { 
            lblErr.innerHTML="正在保存报表，请稍候!Saving Report, please wait......";
            var ifrm=document.getElementById("ifrmRpt");
            ifrm.src="SaveExcelReport.aspx?rptType=" + rptType + "&rptDate=" + txtDate.value;

       }
       else
       {
             return false;
       }      
    }
    event.returnValue=false;

}


function ViewDetail(url)
{
    //alert(url);
    //window.showModalDialog(url,'','dialogHeight:600px;dialogWidth:1200px;center:yes;scroll:auto;hidden;resizable:yes;status:no;');
    var new_window = window.open(url,"_blank","top=0,left=0,menubar=0,resizable=1,scrollbars=yes");
    new_window.resizeTo(screen.availWidth,screen.availHeight);
    return false;

}

//function to set report div width and height
function resizeFunc()
{
    var parentWin=window.parent;
    if (parentWin!=null)
    {
        var ofrm=parentWin.document.getElementById("main");
        if (ofrm!=null)
        {
        
            var sHeight=ofrm.document.body.offsetHeight;
            var sWidth=ofrm.document.body.offsetWidth;
            var divReport=document.getElementById("ctl00_ContentPlaceHolder1_divReport");
            if (divReport!=null)
            {
                divReport.style.width=sWidth-220;
                divReport.style.height=sHeight-205;
            }
            
            divReport=document.getElementById("ctl00_ContentPlaceHolder1_divReport_Quarterly");
            if (divReport!=null)
            {
            
                divReport.style.width=sWidth-230;
                divReport.style.height=sHeight-250;
                
            }
        }
    }
}

//function to set report div width and height
function resizeFunc4Q()
{
    var parentWin=window.parent;
    if (parentWin!=null)
    {
        var ofrm=parentWin.document.getElementById("main");
        if (ofrm!=null)
        {
        
            var sHeight=ofrm.document.body.offsetHeight;
            var sWidth=ofrm.document.body.offsetWidth;
            var divReport=document.getElementById("ctl00_ContentPlaceHolder1_divReport");
            if (divReport!=null)
            {
                divReport.style.width=sWidth-220;
                divReport.style.height=sHeight-240;
            }
            
            divReport=document.getElementById("ctl00_ContentPlaceHolder1_divReport_Quarterly");
            if (divReport!=null)
            {
            
                divReport.style.width=sWidth-215;
                divReport.style.height=sHeight-220;
                
            }
        }
    }
}



function SaveReport(rptType,rptDate)
{
    /* readyState属性能够反映出服务器在处理请求时的进展状况。
    0 = uninitialized
    1 = loading
    2 = loaded
    3 = interactive
    4 = complete
    */
    var lblErr=document.getElementById("ctl00_ContentPlaceHolder1_divError");

    //lblErr.innerHTML="test";
    
    var req;
    try
    {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        req.onreadystatechange =onSaveComplete(req);
        req.open("GET", "SaveExcelReport.aspx?rptType=" + rptType + "&rptDate=" + rptDate, true);
        req.send(null);
    }
    catch(e)
    {
        lblErr.innerHTML="error1";
        return false;
    }
    alert( "SaveExcelReport.aspx?rptType=" + rptType + "&rptDate=" + rptDate);
    

}
function UpdateDeadLine(deadline)
{   
    var pWin=window.parent;
    if (pWin!=null)
    {
        var lblDeadline=pWin.document.getElementById("ctl00_Title1_lblDeadline");
        if (lblDeadline!=null)
            lblDeadline.innerText=deadline;
       
    }
    
    
}   
function onSaveComplete(req)
{
     var lblErr=document.getElementById("ctl00_ContentPlaceHolder1_divError");

     if (req.readyState == 4) 
    {
        /* HTTP status code (i.e., 200, 404, 500, etc.)
        完整的状态值可参考w3c的列表：http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
        我们只关心值为200的OK相应
        */
        if (req.status == 200) 
        {
            if (lblErr!=null)
                lblErr.innerHTML=req.responseText;
        } 
        
        else 
        {
            if (lblErr!=null)
                lblErr.innerHTML=req.responseText;
        }
    }
    else
    {
         lblErr.innerHTML="error2";
    }
}


